public class JPlayerManager {
    private volatile static JPlayerManager instance; //线程安全的
    private static Object object = new Object();

    private JPlayer player1 = new JPlayer("玩家1",JChessType.BLACK);
    private JPlayer player2 = new JPlayer("玩家2",JChessType.WHITE);
    private JPlayer currentPlayer = player1;
    private JPlayerManager(){}

    public static JPlayerManager sharedInstance(){
        if (instance == null){
            synchronized (object) {
                return new JPlayerManager();
            }
        }
        return instance;
    }

    public JPlayer getCurrentPlayer(){
        return currentPlayer;
    }

    public void changePlayer(){
        if (currentPlayer == player1){
            currentPlayer = player2;
        }else{
            currentPlayer = player1;
        }
    }
}
